package com.example.myworkers.service.imp;

import com.example.myworkers.dao.ICar;
import com.example.myworkers.model.Car;
import com.example.myworkers.service.CarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * 编写者：门硕然
 */
@Service
public class CarServiceImpl implements CarService {

    @Autowired
    private ICar carMapper;

    //添加
    @Override
    public int insertCar(Car car) {
    int carValue=0;
    //车辆车牌号不能重复
    Car car1=new Car();
    car1.setLicense(car.getLicense());
    List<Car> getC=carMapper.selectAllCar(car1.getLicense());
    if(getC.size()>=1){
        carValue=-1;
    }else {
        carValue=carMapper.insertCar(car);
    }
        return carValue;
    }

    //查询
    @Override
    public List<Car> selectAllCar(String license) {

        List<Car> getC= carMapper.selectAllCar(license);
        return getC;
    }
    //查询-单个
    @Override
    public Car selectCar(Car car) {
        Car car1=new Car();
        if (car.getCarid()!=0){
            car1=carMapper.selectCar(car);
        }
        return car1;
    }
    //修改
    @Override
    public int updateCar(Car car) {
        int carValue=0;
        //主键不为0
        if(car.getCarid()!=0) {
            //主键信息必须存在
            Car car1=new Car();
            if(carMapper.selectCar(car)!=null){
                //车牌号不能重复
                car1.setLicense(car.getLicense());
                List<Car> getC2=carMapper.selectAllCar(car1.getLicense());
                if(getC2.size()<1){
                   carValue=carMapper.updateCar(car);
                }
            }
        }
        return carValue;
    }
    //删除
    @Override
    public int deleteCar(Car car) {
        int carValue=0;
        //主键不为0
        if(car.getCarid()!=0) {
            carValue=carMapper.deleteCar(car);
        }
        return carValue;
    }




}








